{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example from https://en.wikipedia.org/wiki/Krippendorff's_Alpha\n",
      "\n",
      "*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\n",
      "1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\n",
      "*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\n",
      "\n",
      "Krippendorff's alpha for 类别变量:  0.691358024691358\n",
      "Krippendorff's alpha for 数值变量:  0.8108448928121059\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "import krippendorff\n",
    "\n",
    "print(\"Example from https://en.wikipedia.org/wiki/Krippendorff's_Alpha\")\n",
    "print()\n",
    "reliability_data_str = (\n",
    "        \"*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\",  # 编码员A\n",
    "        \"1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\",  # 编码员B\n",
    "        \"*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\",  # 编码员C\n",
    "    )\n",
    "print(\"\\n\".join(reliability_data_str))\n",
    "print()\n",
    "\n",
    "reliability_data = [\n",
    "        [np.nan if v == \"*\" else int(v) for v in coder.split()] for coder in reliability_data_str]\n",
    "\n",
    "print(\"Krippendorff's alpha for 类别变量: \", krippendorff.alpha(reliability_data=reliability_data,  level_of_measurement=\"nominal\"))\n",
    "print(\"Krippendorff's alpha for 数值变量: \",\n",
    "          krippendorff.alpha(reliability_data=reliability_data))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
